/* ==========================================================================
   Theme panel (puzzle-ux-refresh, design spec section e)
   - .ux-te            the partial's root (_ThemeEditor.cshtml). Layout-agnostic:
                       renders as a self-contained card wherever it is placed.
   - .ux-te-host       the page wrapper (#theme-section) that turns #theme-info
                       (.ux-te-panel) into a right drawer (>= 768px) or a bottom
                       sheet (< 768px). Added by themePanel.js.
   Colours come only from the --t-* theme vars (ux-tokens.css).
   ========================================================================== */

/* ---------------------------------------------------------------- root card */
.theme-editor.ux-te {
    /* undo legacy .theme-editor / .theme-info-mobile .theme-editor rules */
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    position: relative;
    z-index: auto;
    margin: 0;
    padding: 0;
    max-width: none;
    width: min(440px, calc(100vw - 24px));
    min-width: 0;
    box-sizing: border-box;
    text-align: left;
    font-family: var(--ux-font);
    color: var(--t-on-surface);
    background: var(--t-surface);
    border-radius: var(--ux-r-lg);
    box-shadow: var(--ux-inset-top), var(--ux-shadow-2);
    -webkit-tap-highlight-color: transparent;
}

.ux-te *, .ux-te *::before, .ux-te *::after { box-sizing: border-box; }

/* ---------------------------------------------------------------- header */
.ux-te__head {
    flex: none;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 64px;
    padding: 18px 20px 14px;
    box-shadow: 0 1px 0 var(--t-line);
}

.ux-te__heading { min-width: 0; flex: 1 1 auto; }

.ux-te__title {
    margin: 0;
    font: 22px/1.15 var(--ux-font-bold);
    color: var(--t-on-surface);
    letter-spacing: .01em;
}

.ux-te__meta {
    margin: 6px 0 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    font: 14px/1.3 var(--ux-font);
    color: var(--t-on-surface-muted);
}

.ux-te__current {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--t-on-surface);
}

.ux-te__tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border-radius: var(--ux-r-pill);
    background: rgb(255 255 255 / .10);
    font: 11px/1 var(--ux-font-bold);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--t-on-surface-muted);
}

.ux-te__dirty {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: 13px/1 var(--ux-font-bold);
    color: var(--t-on-surface);
}

.ux-te__dirty::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--t-accent-2);
    box-shadow: 0 0 0 3px var(--t-glow-soft);
}

.ux-te__tag[hidden], .ux-te__dirty[hidden], .ux-te [hidden] { display: none !important; }

.ux-te__close {
    display: none; /* only inside a drawer/sheet host */
    flex: none;
    width: 40px;
    height: 40px;
    margin: -6px -8px 0 auto;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--t-on-surface);
    place-items: center;
    cursor: pointer;
    transition: background-color var(--ux-d-fast), transform var(--ux-d-instant) var(--ux-ease-out);
}

.ux-te__close:hover { background: rgb(255 255 255 / .10); }
.ux-te__close:active { transform: scale(.92); }
.ux-te-host .ux-te__close { display: grid; }

/* ---------------------------------------------------------------- body + sections */
.ux-te__body {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 18px 20px 22px;
}

.ux-te__section { min-width: 0; }

.ux-te__label {
    margin: 0 0 10px;
    font: 12px/1 var(--ux-font-bold);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--t-on-surface-muted);
}

.ux-te__hint {
    margin: 10px 0 0;
    font: 13px/1.35 var(--ux-font);
    color: var(--t-on-surface);
}

/* focus ring shared by every control */
.ux-te [role="radio"]:focus-visible,
.ux-te [role="switch"]:focus-visible,
.ux-te button:focus-visible,
.ux-te a:focus-visible,
.ux-te .ux-te__input:focus-visible {
    outline: 2px solid var(--t-accent-2);
    outline-offset: 2px;
}

.ux-te [role="radio"]:focus { outline: none; }
.ux-te [role="radio"]:focus-visible { outline: 2px solid var(--t-accent-2); outline-offset: 2px; }

/* ---------------------------------------------------------------- theme cards */
.ux-te__themes {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 10px;
}

.ux-te-card {
    position: relative;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 6px;
    border-radius: 14px;
    background: rgb(255 255 255 / .06);
    box-shadow: inset 0 0 0 1px var(--t-line);
    cursor: pointer;
    user-select: none;
    transition: transform var(--ux-d-fast) var(--ux-ease-out), background-color var(--ux-d-fast), box-shadow var(--ux-d-fast);
}

.ux-te-card:hover { transform: translateY(-2px); background: rgb(255 255 255 / .10); }
.ux-te-card:active { transform: translateY(0) scale(.98); transition-duration: var(--ux-d-instant); }

.ux-te-card.is-selected {
    background: color-mix(in srgb, var(--t-accent-2) 14%, rgb(255 255 255 / .04));
    box-shadow: inset 0 0 0 2px var(--t-accent-2);
}

.ux-te-card__preview {
    position: relative;
    height: 72px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    overflow: hidden;
    background: var(--c-bg);
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / .08);
}

.ux-te-card__board {
    width: 52px;
    height: 52px;
    border-radius: 6px;
    background: conic-gradient(var(--c-d) 25%, var(--c-l) 0 50%, var(--c-d) 0 75%, var(--c-l) 0) 0 0 / 50% 50%;
    box-shadow: 0 4px 10px rgb(0 0 0 / .35);
}

.ux-te-card__dots {
    position: absolute;
    right: 6px;
    bottom: 6px;
    display: flex;
    gap: 3px;
}

.ux-te-card__dots i {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 1px rgb(0 0 0 / .25);
}

.ux-te-card__dots i:nth-child(1) { background: var(--c-a1); }
.ux-te-card__dots i:nth-child(2) { background: var(--c-a2); }
.ux-te-card__dots i:nth-child(3) { background: var(--c-a4); }

.ux-te-card__name {
    padding: 0 3px 2px;
    font: 13px/1.25 var(--ux-font);
    color: var(--t-on-surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ux-te-card__tag {
    position: absolute;
    top: 5px;
    left: 5px;
    padding: 3px 5px;
    border-radius: 6px;
    background: rgb(0 0 0 / .5);
    font: 9px/1 var(--ux-font-bold);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #fff;
}

.ux-te-card__plus { display: none; }

.ux-te-card__check,
.ux-te-fx__check {
    position: absolute;
    display: grid;
    place-items: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--t-accent-2);
    color: var(--t-on-accent-2);
    box-shadow: 0 2px 6px rgb(0 0 0 / .35);
    transform: scale(0);
    transition: transform var(--ux-d-base) var(--ux-ease-spring);
    pointer-events: none;
}

.ux-te-card__check { top: -6px; right: -6px; }
.ux-te-card.is-selected .ux-te-card__check,
.ux-te-fx.is-selected .ux-te-fx__check { transform: scale(1); }

/* empty custom slots: dashed "+" */
.ux-te-card.is-empty {
    background: transparent;
    box-shadow: inset 0 0 0 1.5px var(--t-line-strong);
    background-image: none;
}

.ux-te-card.is-empty { box-shadow: none; outline: 1.5px dashed var(--t-line-strong); outline-offset: -1.5px; }
.ux-te-card.is-empty:focus-visible { outline: 2px solid var(--t-accent-2); outline-offset: 2px; }
.ux-te-card.is-empty.is-selected { outline: 2px solid var(--t-accent-2); outline-offset: -2px; }
.ux-te-card.is-empty .ux-te-card__preview { background: transparent; box-shadow: none; }
.ux-te-card.is-empty .ux-te-card__board,
.ux-te-card.is-empty .ux-te-card__dots { display: none; }
.ux-te-card.is-empty .ux-te-card__plus {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: rgb(255 255 255 / .08);
    font: 24px/1 var(--ux-font);
    color: var(--t-on-surface-muted);
    transition: transform var(--ux-d-fast) var(--ux-ease-spring), background-color var(--ux-d-fast);
}
.ux-te-card.is-empty:hover .ux-te-card__plus { transform: scale(1.1); background: rgb(255 255 255 / .14); }
.ux-te-card.is-empty .ux-te-card__name { color: var(--t-on-surface-muted); }

/* "pick one of your custom themes" pulse */
@media (prefers-reduced-motion: no-preference) {
    .ux-te-card.is-pulse { animation: ux-te-pulse 600ms var(--ux-ease-out) 3; }
}
.ux-te-card.is-pulse { box-shadow: inset 0 0 0 2px var(--t-accent-2); }

@keyframes ux-te-pulse {
    0%, 100% { transform: none; }
    40% { transform: translateY(-3px) scale(1.03); }
}

/* ---------------------------------------------------------------- name field */
.ux-te__name-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 14px;
}

.ux-te__field-label {
    font: 12px/1 var(--ux-font-bold);
    letter-spacing: .04em;
    color: var(--t-on-surface-muted);
}

.ux-te .ux-te__input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    border: 0;
    border-radius: 12px;
    background: var(--t-surface-sunken);
    box-shadow: inset 0 0 0 1px var(--t-line);
    font: 16px/1 var(--ux-font);
    color: var(--t-on-surface);
    opacity: 1;
    transition: box-shadow var(--ux-d-fast);
}

.ux-te .ux-te__input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--t-accent-2); }

/* ---------------------------------------------------------------- piece chips */
.ux-te__chips {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(50px, 1fr));
    gap: 6px;
}

.ux-te-chip {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 6px 4px;
    border-radius: 12px;
    background: rgb(255 255 255 / .06);
    cursor: pointer;
    user-select: none;
    transition: transform var(--ux-d-fast) var(--ux-ease-spring), background-color var(--ux-d-fast), box-shadow var(--ux-d-fast), opacity var(--ux-d-fast);
}

.ux-te-chip:hover { transform: translateY(-2px); background: rgb(255 255 255 / .10); }
.ux-te-chip:active { transform: scale(.95); }

.ux-te-chip__img {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 9px;
    background: var(--t-light);
    box-shadow: inset 0 -10px 16px -10px rgb(0 0 0 / .25);
}

.ux-te-chip__img img { width: 32px; height: 32px; pointer-events: none; }

.ux-te-chip__label {
    max-width: 100%;
    font: 11px/1.15 var(--ux-font);
    color: var(--t-on-surface-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ux-te-chip.is-selected {
    background: color-mix(in srgb, var(--t-accent-2) 16%, rgb(255 255 255 / .04));
    box-shadow: inset 0 0 0 2px var(--t-accent-2);
}

.ux-te-chip.is-selected .ux-te-chip__label { color: var(--t-on-surface); }

/* ---------------------------------------------------------------- effect tiles */
.ux-te__effects {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px;
}

.ux-te-fx {
    position: relative;
    height: 72px;
    border-radius: 12px;
    overflow: hidden;
    isolation: isolate;
    background: var(--t-bg);
    box-shadow: inset 0 0 0 1px var(--t-line);
    cursor: pointer;
    user-select: none;
    transition: transform var(--ux-d-fast) var(--ux-ease-out), box-shadow var(--ux-d-fast), opacity var(--ux-d-fast);
}

.ux-te-fx:hover { transform: translateY(-2px); }
.ux-te-fx:active { transform: scale(.97); }
.ux-te-fx.is-selected { box-shadow: inset 0 0 0 2px var(--t-accent-2); }

.ux-te-fx::after { /* keeps the label legible over the art */
    content: "";
    position: absolute;
    inset: auto 0 0 0;
    height: 30px;
    background: linear-gradient(to top, color-mix(in srgb, var(--t-bg) 85%, transparent), transparent);
    z-index: 1;
    pointer-events: none;
}

.ux-te-fx__label {
    position: absolute;
    left: 9px;
    right: 9px;
    bottom: 7px;
    z-index: 2;
    font: 13px/1.15 var(--ux-font);
    color: var(--t-on-bg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ux-te-fx__check { top: 6px; right: 6px; width: 18px; height: 18px; z-index: 2; }

.ux-te-fx__art { position: absolute; inset: 0; pointer-events: none; }
.ux-te-fx__art i { position: absolute; display: block; font-style: normal; }

/* static frames (also the reduced-motion look) */
.fx-snow i { left: var(--x); top: 20%; width: var(--s); height: var(--s); border-radius: 50%; background: #fff; opacity: .9; transform: translateY(calc(var(--d) * -12px)); }
.fx-bubbles i { left: var(--x); top: 50%; width: var(--s); height: var(--s); border-radius: 50%;
    background: color-mix(in srgb, var(--t-accent-2) 22%, transparent); box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--t-accent-2) 80%, transparent); transform: translateY(calc(var(--d) * 10px)); }
.fx-aurora i { left: var(--x); top: var(--y); width: 160%; height: 26px; border-radius: 50%; opacity: .75;
    background: radial-gradient(closest-side, color-mix(in srgb, var(--t-accent-2) 70%, transparent), transparent); }
.fx-aurora i:nth-child(2) { background: radial-gradient(closest-side, color-mix(in oklab, var(--t-accent-2), #8a6cff 65%), transparent); opacity: .55; }
.fx-fireflies i { left: var(--x); top: var(--y); width: var(--s); height: var(--s); border-radius: 50%;
    background: color-mix(in oklab, var(--t-accent-2), #ffe08a 70%);
    box-shadow: 0 0 6px 2px color-mix(in oklab, var(--t-accent-2), #ffd36b 60%); }
.fx-stars i { left: var(--x); top: var(--y); width: var(--s); height: var(--s); border-radius: 50%; background: #fff; opacity: .8; }
.fx-bokeh i { left: var(--x); top: var(--y); width: var(--s); height: var(--s); border-radius: 50%; opacity: .5;
    background: radial-gradient(circle, color-mix(in srgb, var(--t-accent-2) 80%, transparent) 0 55%, transparent 72%); }
.fx-bokeh i:nth-child(2n) { background: radial-gradient(circle, color-mix(in srgb, var(--t-accent-4) 80%, transparent) 0 55%, transparent 72%); }
.fx-bokeh i:nth-child(3n) { background: radial-gradient(circle, color-mix(in srgb, var(--t-light) 70%, transparent) 0 55%, transparent 72%); }
.fx-petals i { left: var(--x); top: 25%; width: var(--s); height: calc(var(--s) * .7); border-radius: 80% 0 80% 0;
    background: color-mix(in oklab, var(--t-accent-4), #ffd1dc 55%); opacity: .9; transform: rotate(30deg); }
.fx-pieces i { left: var(--x); top: 22%; font-size: var(--s); line-height: 1; color: var(--t-light); opacity: .55; }
.fx-generic i { left: var(--x); top: var(--y); width: var(--s); height: var(--s); border-radius: 50%; background: var(--t-accent-2); opacity: .8; }

.ux-te-fx__none,
.ux-te-fx__sparkle {
    position: absolute;
    left: 50%;
    top: 38%;
    transform: translate(-50%, -50%);
    font: 26px/1 var(--ux-font);
    color: var(--t-on-bg-muted);
}

.ux-te-fx__sparkle { color: var(--t-accent-2); font-size: 24px; }

/* live previews: only while the panel is visible and motion is welcome */
@media (prefers-reduced-motion: no-preference) {
    .ux-te .fx-snow i { animation: ux-te-fall var(--t) linear var(--d) infinite; }
    .ux-te .fx-bubbles i { animation: ux-te-rise var(--t) var(--ux-ease-in-out) var(--d) infinite; }
    .ux-te .fx-aurora i { animation: ux-te-sway var(--t) ease-in-out var(--d) infinite alternate; }
    .ux-te .fx-fireflies i { animation: ux-te-wander var(--t) ease-in-out var(--d) infinite alternate, ux-te-blink calc(var(--t) * .7) ease-in-out var(--d) infinite alternate; }
    .ux-te .fx-stars i,
    .ux-te .fx-generic i { animation: ux-te-blink var(--t) ease-in-out var(--d) infinite alternate; }
    .ux-te .fx-bokeh i { animation: ux-te-float var(--t) ease-in-out var(--d) infinite alternate; }
    .ux-te .fx-petals i { animation: ux-te-petal var(--t) linear var(--d) infinite; }
    .ux-te .fx-pieces i { animation: ux-te-drift var(--t) linear var(--d) infinite; }
    .ux-te .ux-te-fx__sparkle { animation: ux-te-twinkle 2.4s ease-in-out infinite; }

    /* paused (removed) while a hosted panel is closed */
    .ux-te-host:not(.is-open) .ux-te-fx__art i,
    .ux-te-host:not(.is-open) .ux-te-fx__sparkle { animation: none; }
}

@keyframes ux-te-fall { from { transform: translate3d(0, -36px, 0); } to { transform: translate3d(6px, 70px, 0); } }
@keyframes ux-te-rise {
    0% { transform: translate3d(0, 46px, 0); opacity: 0; }
    15% { opacity: 1; }
    50% { transform: translate3d(4px, 0, 0); }
    100% { transform: translate3d(-3px, -60px, 0); opacity: 0; }
}
@keyframes ux-te-sway { from { transform: translate3d(-8%, 0, 0) scaleY(.8); } to { transform: translate3d(10%, 4px, 0) scaleY(1.15); } }
@keyframes ux-te-wander { from { transform: translate3d(-5px, 3px, 0); } to { transform: translate3d(6px, -6px, 0); } }
@keyframes ux-te-blink { from { opacity: .15; } to { opacity: 1; } }
@keyframes ux-te-float { from { transform: translate3d(-4px, 4px, 0) scale(.9); } to { transform: translate3d(6px, -5px, 0) scale(1.08); } }
@keyframes ux-te-petal {
    from { transform: translate3d(-6px, -30px, 0) rotate(0deg); opacity: 0; }
    15% { opacity: .95; }
    to { transform: translate3d(14px, 64px, 0) rotate(260deg); opacity: .9; }
}
@keyframes ux-te-drift {
    0% { transform: translate3d(0, 60px, 0) rotate(-8deg); opacity: 0; }
    20% { opacity: .6; }
    80% { opacity: .6; }
    100% { transform: translate3d(4px, -40px, 0) rotate(8deg); opacity: 0; }
}
@keyframes ux-te-twinkle { 0%, 100% { transform: translate(-50%, -50%) scale(.85) rotate(0deg); opacity: .7; } 50% { transform: translate(-50%, -50%) scale(1.1) rotate(20deg); opacity: 1; } }

/* ---------------------------------------------------------------- flip switch */
.ux-te__switch-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 52px;
    padding: 8px 10px 8px 14px;
    border-radius: 12px;
    background: rgb(255 255 255 / .05);
    cursor: pointer;
    transition: opacity var(--ux-d-fast);
}

.ux-te__switch-label { font: 15px/1.3 var(--ux-font); color: var(--t-on-surface); }

.ux-te__switch {
    position: relative;
    flex: none;
    width: 48px;
    height: 28px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: var(--ux-r-pill);
    background: rgb(255 255 255 / .18);
    cursor: pointer;
    transition: background-color var(--ux-d-base) var(--ux-ease-out);
}

.ux-te__switch[aria-checked="true"] { background: var(--t-accent-2); }

.ux-te__switch-thumb {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgb(0 0 0 / .35);
    transition: transform var(--ux-d-base) var(--ux-ease-spring);
}

.ux-te__switch[aria-checked="true"] .ux-te__switch-thumb { transform: translateX(20px); }

/* ---------------------------------------------------------------- colours */
.ux-te__callout {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 12px;
    margin: 0 0 14px;
    padding: 12px 12px 12px 14px;
    border-radius: 14px;
    background: var(--t-surface-sunken);
    box-shadow: inset 0 0 0 1px var(--t-line);
}

.ux-te__callout-text {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font: 14px/1.35 var(--ux-font);
    color: var(--t-on-surface);
}

.ux-te__callout-text svg { flex: none; color: var(--t-accent-2); }

/* Inline "replace an unsaved custom slot?" confirm, shown under the callout. */
.ux-te__confirm {
    margin: -4px 0 14px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--t-surface-sunken);
    box-shadow: inset 0 0 0 1px var(--t-accent-2);
}

.ux-te__confirm-text {
    margin: 0 0 10px;
    font: 14px/1.35 var(--ux-font);
    color: var(--t-on-surface);
    overflow-wrap: anywhere;
}

.ux-te__confirm-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

@media (prefers-reduced-motion: no-preference) {
    .ux-te__callout.is-nudge { animation: ux-te-shake 240ms cubic-bezier(.36, .07, .19, .97); }
}

@keyframes ux-te-shake {
    0%, 100% { transform: none; }
    20% { transform: translateX(-6px); }
    45% { transform: translateX(5px); }
    70% { transform: translateX(-3px); }
    90% { transform: translateX(1px); }
}

.ux-te__group + .ux-te__group { margin-top: 10px; padding-top: 10px; box-shadow: 0 -1px 0 var(--t-line); }

.ux-te__group-label {
    margin: 4px 0 4px 8px;
    font: 11px/1 var(--ux-font-bold);
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--t-on-surface-faint);
}

.ux-te__colour-grid { /* flex-wrap, not grid: the inline picker (a row-wrap flex box) is mis-measured as a grid item */
    display: flex;
    flex-wrap: wrap;
    gap: 2px 8px;
}

.ux-te__colour-grid > .ux-te__colour-row { flex: 1 1 calc(50% - 8px); min-width: 150px; }

.ux-te__colour-row {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    min-height: 52px;
    padding: 8px;
    border-radius: 12px;
    cursor: pointer;
    transition: background-color var(--ux-d-fast), opacity var(--ux-d-fast);
}

.ux-te__colour-row:hover { background: rgb(255 255 255 / .06); }

.ux-te .picker-button {
    flex: none;
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 10px;
    box-shadow: inset 0 0 0 1px rgb(255 255 255 / .25), 0 2px 6px rgb(0 0 0 / .3);
    cursor: pointer;
    transition: transform var(--ux-d-fast) var(--ux-ease-spring);
}

.ux-te__colour-row:hover .picker-button:not(:disabled) { transform: scale(1.06); }
.ux-te .picker-button:disabled { pointer-events: none; cursor: default; }

.ux-te__colour-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }

.ux-te__colour-name {
    font: 15px/1.2 var(--ux-font);
    color: var(--t-on-surface);
    overflow-wrap: anywhere;
}

.ux-te__colour-caption {
    font: 12px/1.25 var(--ux-font);
    color: var(--t-on-surface-muted);
}

@media (prefers-reduced-motion: no-preference) {
    [data-ux-te-colours].is-unlocked .picker-button { animation: ux-te-pop 420ms var(--ux-ease-spring); }
}
@keyframes ux-te-pop { 0% { transform: scale(.7); } 100% { transform: scale(1); } }

/* vanilla-picker opens inline under its row, full width, in a sunken well */
.ux-te .picker_wrapper {
    flex: 1 1 100%;
    width: 100% !important;
    max-width: none !important;
    margin: 4px 0 8px !important;
    padding: 12px !important;
    border-radius: 12px;
    background: var(--t-surface-sunken) !important;
    box-shadow: inset 0 0 0 1px var(--t-line) !important;
    font-size: 11px;
}

/* fixed height: a %-padding square collapses inside the grid's intrinsic sizing and overflows the well */
.ux-te .picker_sl { flex: 1 1 100%; height: 168px; }
.ux-te .picker_sl::before { display: none; }
.ux-te .picker_sl, .ux-te .picker_hue { border-radius: 8px; }
.ux-te .picker_editor { width: calc(100% - 1em) !important; }
.ux-te .picker_editor input { color: var(--t-on-surface); border-radius: 8px; }

/* ---------------------------------------------------------------- locked (built-in) */
.ux-te.is-locked .ux-te-chip,
.ux-te.is-locked .ux-te-fx,
.ux-te.is-locked .ux-te__switch-row,
.ux-te.is-locked .ux-te__colour-row { opacity: .5; }

.ux-te.is-locked .ux-te-chip:hover,
.ux-te.is-locked .ux-te-fx:hover { transform: none; }

.ux-te.is-locked .ux-te-chip.is-selected,
.ux-te.is-locked .ux-te-fx.is-selected { opacity: .75; }

/* ---------------------------------------------------------------- buttons + footer */
.ux-te-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    margin: 0;
    padding: 10px 18px;
    border: 0;
    border-radius: 12px;
    font: 16px/1.1 var(--ux-font-bold);
    text-align: center;
    text-decoration: none !important;
    cursor: pointer;
    opacity: 1;
    transition: transform var(--ux-d-instant) var(--ux-ease-out), background-color var(--ux-d-fast), box-shadow var(--ux-d-fast), opacity var(--ux-d-fast);
}

.ux-te-btn:active { transform: scale(.97); }

.ux-te-btn--primary,
.ux-te-btn--save:not(:disabled) {
    background: var(--t-accent-2);
    color: var(--t-on-accent-2) !important;
    box-shadow: 0 4px 14px -4px var(--t-glow);
}

.ux-te-btn--primary:hover,
.ux-te-btn--save:not(:disabled):hover { background: color-mix(in oklab, var(--t-accent-2), white 12%); }

.ux-te-btn--secondary,
.ux-te-btn--save:disabled {
    background: rgb(255 255 255 / .08);
    color: var(--t-on-surface);
    box-shadow: inset 0 0 0 1px var(--t-line);
}

.ux-te-btn--secondary:hover:not(:disabled) { background: rgb(255 255 255 / .14); }

.ux-te-btn:disabled { opacity: .5; cursor: default; pointer-events: none; }
.ux-te-btn--save:disabled { opacity: .75; }

.ux-te-btn--save:disabled .ux-te__when-dirty,
.ux-te-btn--save:not(:disabled) .ux-te__when-clean { display: none; }

/* Signed-in non-member editing a custom slot: Save becomes "Become a member to save" (themePanel.js toggles .is-member-locked). */
.ux-te-btn--save .ux-te__when-member,
.ux-te.is-member-locked .ux-te-btn--save .ux-te__when-dirty,
.ux-te.is-member-locked .ux-te-btn--save .ux-te__when-clean { display: none; }
.ux-te.is-member-locked .ux-te-btn--save .ux-te__when-member { display: inline; }

.ux-te__save-error {
    flex: 1 0 100%;
    margin: 0;
    font: 13px/1.35 var(--ux-font-bold);
    color: var(--t-on-surface);
    overflow-wrap: anywhere;
}

.ux-te__save-error::before { content: "\26A0\FE0E  "; color: rgb(255 120 100); }

#theme-use-button.is-in-use::after { content: " \2713"; }

.ux-te-btn.is-highlight {
    background: var(--t-accent-2);
    color: var(--t-on-accent-2);
    box-shadow: 0 0 0 4px var(--t-glow-soft);
}

.ux-te__foot {
    flex: none;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    min-height: 72px;
    padding: 14px 20px;
    border-radius: 0 0 var(--ux-r-lg) var(--ux-r-lg);
    background: color-mix(in srgb, var(--t-surface-strong) 90%, transparent);
    box-shadow: 0 -1px 0 var(--t-line);
}

.ux-te__foot-end { margin-left: auto; display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

.ux-te__login-note {
    flex: 1 1 140px;
    font: 13px/1.35 var(--ux-font);
    color: var(--t-on-surface-muted);
}

.ux-te__live { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ==========================================================================
   Host: right drawer (.is-drawer) or bottom sheet (.is-sheet). Lives on the
   page's #theme-section; the partial above stays layout-agnostic.
   themePanel.js picks the mode from real geometry at open time and on resize:
   sheet below 768px, or whenever the drawer can't sit beside the board even
   after the maximum stage shift (e.g. portrait tablets).
   ========================================================================== */
#theme-section.ux-te-host {
    position: static;
    display: block !important;
    width: 0 !important;
    min-width: 0 !important;
    height: 0;
    margin: 0 !important;
    padding: 0;
    overflow: visible;
}

.ux-te-host .ux-te-panel {
    position: fixed;
    z-index: var(--ux-z-panel);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin: 0;
    opacity: 0;
    visibility: hidden;
    animation: none;
}

.ux-te-host .ux-te-panel:focus { outline: none; }

.ux-te-host .theme-editor.ux-te {
    flex: 1 1 auto;
    min-height: 0;
    width: auto;
    background: transparent;
    border-radius: inherit;
    box-shadow: none;
}

.ux-te-host .ux-te__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: rgb(255 255 255 / .25) transparent;
}

.ux-te-host .ux-te__foot { border-radius: 0; }

.ux-te-grip { display: none; }
.ux-te-backdrop { display: none; }

/* mode switch while open (resize / rotation): jump, don't fly across the screen */
.ux-te-host.is-switching .ux-te-panel,
.ux-te-host.is-switching .ux-te-backdrop { transition: none !important; }

/* ---------------------------------------------------------------- drawer */
.ux-te-host.is-drawer .ux-te-panel {
    top: 78px;
    right: 12px;
    bottom: 12px;
    width: min(440px, calc(100vw - 24px));
    border-radius: var(--ux-r-lg);
    transform: translate3d(calc(100% + 24px), 0, 0);
    transition: transform 260ms var(--ux-ease-in), opacity 260ms var(--ux-ease-in), visibility 0s linear 260ms;
}

.ux-te-host.is-drawer.is-open .ux-te-panel {
    transform: none;
    opacity: 1;
    visibility: visible;
    transition: transform 420ms var(--ux-ease-emph), opacity 280ms var(--ux-ease-out), visibility 0s;
}

/* ---------------------------------------------------------------- sheet */
.ux-te-host.is-sheet .ux-te-panel {
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 680px;           /* tablets: a centred sheet, not a full-width slab */
    margin: 0 auto;
    height: 88vh;
    height: 88svh;
    z-index: var(--ux-z-sheet);
    border-radius: 20px 20px 0 0;
    opacity: 1;
    transform: translate3d(0, calc(100% + 24px), 0);
    transition: transform 280ms var(--ux-ease-in), visibility 0s linear 280ms;
}

/* peek: --ux-te-peek is the visible height (JS sets it from the free space under the board card, max 42svh) */
.ux-te-host.is-sheet.is-open .ux-te-panel {
    visibility: visible;
    transform: translate3d(0, calc(100% - 42vh), 0);
    transform: translate3d(0, calc(100% - var(--ux-te-peek, 42svh)), 0);
    transition: transform 320ms var(--ux-ease-in-out), visibility 0s;
}

.ux-te-host.is-sheet.is-open[data-snap="full"] .ux-te-panel { transform: translate3d(0, 0, 0); }

.ux-te-host.is-sheet.is-dragging .ux-te-panel { transition: none; }

.ux-te-host.is-sheet .ux-te-grip {
    display: flex;
    flex: none;
    justify-content: center;
    align-items: center;
    height: 22px;
    padding-top: 6px;
    touch-action: none;
    cursor: grab;
}

.ux-te-host.is-sheet .ux-te-grip span {
    width: 36px;
    height: 5px;
    border-radius: 3px;
    background: rgb(255 255 255 / .35);
}

.ux-te-host.is-sheet .ux-te__head {
    min-height: 0;
    padding: 6px 16px 12px;
    touch-action: none;
    cursor: grab;
}

.ux-te-host.is-sheet .ux-te__title { font-size: 20px; }
.ux-te-host.is-sheet .ux-te__meta { margin-top: 3px; }
.ux-te-host.is-sheet .ux-te__body { padding: 14px 16px 20px; gap: 22px; }
.ux-te-host.is-sheet .ux-te__foot { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); min-height: 0; }

/* one swipeable row of theme cards and of piece chips */
.ux-te-host.is-sheet .ux-te__themes,
.ux-te-host.is-sheet .ux-te__chips {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x mandatory;
    scroll-padding: 0 16px;
    margin: 0 -16px;
    padding: 6px 16px 8px;
    scrollbar-width: none;
}

.ux-te-host.is-sheet .ux-te__themes::-webkit-scrollbar,
.ux-te-host.is-sheet .ux-te__chips::-webkit-scrollbar { display: none; }

.ux-te-host.is-sheet .ux-te-card { flex: 0 0 112px; scroll-snap-align: start; }
.ux-te-host.is-sheet .ux-te-chip { flex: 0 0 58px; scroll-snap-align: start; }
.ux-te-host.is-sheet .ux-te__effects { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.ux-te-host.is-sheet .ux-te__login { flex: 1 1 auto; }

.ux-te-host.is-sheet .ux-te-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: var(--ux-z-sheet-backdrop);
    background: rgb(0 0 0 / .35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 280ms var(--ux-ease-out);
}

.ux-te-host.is-sheet.is-open[data-snap="full"] .ux-te-backdrop { opacity: 1; pointer-events: auto; }

@media (prefers-reduced-motion: reduce) {
    /* opacity only */
    .ux-te-host.is-drawer .ux-te-panel,
    .ux-te-host.is-drawer.is-open .ux-te-panel { transform: none; }
    .ux-te-host .ux-te-panel { transition: opacity 160ms linear, visibility 0s linear 160ms !important; }
    .ux-te-host.is-open .ux-te-panel { transition: opacity 160ms linear, visibility 0s !important; }
    .ux-te-host.is-dragging .ux-te-panel { transition: none !important; }
    .ux-te-host:not(.is-open) .ux-te-panel { opacity: 0; }
    .ux-te-host.is-open .ux-te-panel { opacity: 1; }

    .ux-te-card, .ux-te-chip, .ux-te-fx { transition: none; }
    .ux-te-card:hover, .ux-te-chip:hover, .ux-te-fx:hover { transform: none; }
}
