/* ============================================================
   sw-compose.css — Compose mode (Stage 3B)
   ------------------------------------------------------------
   Compose mode = "what objects are on the page". It is the
   sibling of the 🎨 Customize panel (which is now design-only).

   When sw-compose.js activates, it adds `.sw-compose-on` to
   <body>. That class:
     - reveals per-object ✕ / Move chrome on every [data-section-id]
     - slides up the fixed object-bank tray at the bottom
   The "dust-trail" motion layer is a Road-Runner-style bounce +
   fade + puff that animates toward / from the object bank.

   Tokens only: var(--sp-*), var(--r-*), var(--accent), var(--card),
   var(--text), var(--border). No bold (font-weight <= 500).
   Logical properties throughout so RTL just works.
   ============================================================ */

/* ---- token fallbacks (in case a page hasn't defined the scale) ---- */
.sw-compose-on,
.sw-compose-tray,
.sw-compose-trail {
    --swc-gap: var(--sp-3, 12px);
    --swc-radius: var(--r-2, 10px);
    --swc-accent: var(--accent, #c8a951);
    --swc-danger: #e11d48;
    --swc-ease: cubic-bezier(.34, 1.56, .64, 1);
}

/* ============================================================
   1. Page state while Compose mode is on
   ============================================================ */

/* Lift the page so the fixed bottom tray never covers content. */
body.sw-compose-on {
    padding-bottom: 168px;
    transition: padding-bottom .22s ease;
}

/* Every reorderable object gets a soft dashed "editable" outline so
   the user can see exactly which blocks Compose can manage. */
body.sw-compose-on [data-section-id] {
    position: relative;
    outline: 2px dashed color-mix(in srgb, var(--swc-accent) 55%, transparent);
    outline-offset: 4px;
    border-radius: var(--swc-radius);
    transition: outline-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
body.sw-compose-on [data-section-id]:hover {
    outline-color: var(--swc-accent);
    box-shadow: 0 6px 22px rgba(0, 0, 0, .12);
}

/* The section currently being moved / dragged. */
body.sw-compose-on [data-section-id].swc-dragging {
    opacity: .45;
    outline-style: solid;
}
body.sw-compose-on [data-section-id].swc-move-armed {
    outline-color: var(--swc-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--swc-accent) 30%, transparent);
}

/* ============================================================
   2. Per-object chrome — ✕ remove + Move handle
   ============================================================ */

.swc-chrome {
    position: absolute;
    inset-block-start: -14px;
    inset-inline-end: 8px;
    display: flex;
    gap: 6px;
    z-index: 40;
    /* Hidden until compose mode is on (chrome is injected once and
       stays in the DOM; visibility is class-driven). */
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s ease;
}
body.sw-compose-on .swc-chrome {
    opacity: 1;
    pointer-events: auto;
}

.swc-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: .8rem;
    font-weight: 500;
    line-height: 1;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border, #e2e8f0);
    background: var(--card, #fff);
    color: var(--text, #1a1a2e);
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .16);
    transition: transform .12s ease, background .12s ease, color .12s ease;
}
.swc-btn:hover { transform: translateY(-1px); }
.swc-btn:active { transform: translateY(0); }

.swc-btn-remove {
    inline-size: 30px;
    block-size: 30px;
    padding: 0;
    justify-content: center;
    font-size: .95rem;
    color: var(--swc-danger);
    border-color: color-mix(in srgb, var(--swc-danger) 40%, var(--border, #e2e8f0));
}
.swc-btn-remove:hover {
    background: var(--swc-danger);
    color: #fff;
}

.swc-btn-move {
    background: color-mix(in srgb, var(--swc-accent) 16%, var(--card, #fff));
    border-color: color-mix(in srgb, var(--swc-accent) 50%, var(--border, #e2e8f0));
}
.swc-btn-move.swc-armed {
    background: var(--swc-accent);
    color: #1a1a2e;
}

/* ============================================================
   3. Move drop-slots — "press here to move here"
   ============================================================ */

.swc-slot {
    block-size: 0;
    margin-block: 0;
    border-radius: var(--swc-radius);
    border: 2px dashed transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    color: var(--swc-accent);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    background: color-mix(in srgb, var(--swc-accent) 8%, transparent);
    transition: block-size .18s var(--swc-ease), margin-block .18s ease,
                border-color .15s ease, background .15s ease;
}
.swc-slot.swc-slot-live {
    block-size: 46px;
    margin-block: 10px;
    border-color: color-mix(in srgb, var(--swc-accent) 60%, transparent);
}
.swc-slot.swc-slot-live:hover {
    background: color-mix(in srgb, var(--swc-accent) 20%, transparent);
    border-color: var(--swc-accent);
}
.swc-slot-label { pointer-events: none; }

/* "return / stay" affordance shown right after a move. */
.swc-undo-bar {
    position: absolute;
    inset-block-start: -14px;
    inset-inline-start: 8px;
    display: flex;
    gap: 6px;
    z-index: 41;
    animation: swc-pop-in .25s var(--swc-ease) both;
}
.swc-undo-bar .swc-btn { box-shadow: 0 4px 14px rgba(0, 0, 0, .22); }

/* ============================================================
   4. Object bank — fixed bottom tray
   ============================================================ */

.sw-compose-tray {
    position: fixed;
    inset-inline: 0;
    inset-block-end: 0;
    z-index: 92; /* below the nav stack (101/102), above page content */
    background: var(--card, #fff);
    border-block-start: 1px solid var(--border, #e2e8f0);
    box-shadow: 0 -8px 24px rgba(0, 0, 0, .16);
    padding: 12px 18px 14px;
    transform: translateY(110%);
    transition: transform .26s var(--swc-ease);
}
body.sw-compose-on .sw-compose-tray { transform: translateY(0); }

.sw-compose-tray-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-block-end: 8px;
}
.sw-compose-tray-title {
    font-size: .92rem;
    font-weight: 500;
    color: var(--text, #1a1a2e);
    margin: 0;
}
.sw-compose-tray-hint {
    font-size: .76rem;
    color: var(--text-muted, #64748b);
    margin: 0;
}
.sw-compose-tray-done {
    margin-inline-start: auto;
    font-size: .82rem;
    font-weight: 500;
    padding: 7px 16px;
    border-radius: 999px;
    border: 0;
    cursor: pointer;
    background: var(--swc-accent);
    color: #1a1a2e;
    transition: transform .12s ease, filter .12s ease;
}
.sw-compose-tray-done:hover { transform: translateY(-1px); filter: brightness(1.05); }

.sw-compose-bank {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    max-block-size: 92px;
    overflow-y: auto;
}
.sw-compose-bank-empty {
    font-size: .8rem;
    color: var(--text-muted, #64748b);
    padding: 8px 4px;
}

/* A removed object, sitting in the bank as a draggable chip. */
.swc-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: .82rem;
    font-weight: 500;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--border, #e2e8f0);
    background: color-mix(in srgb, var(--swc-accent) 10%, var(--card, #fff));
    color: var(--text, #1a1a2e);
    cursor: grab;
    transition: transform .12s ease, box-shadow .12s ease;
}
.swc-chip:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 16px rgba(0, 0, 0, .16);
}
.swc-chip:active { cursor: grabbing; }
.swc-chip-restore {
    inline-size: 20px;
    block-size: 20px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .72rem;
    background: var(--swc-accent);
    color: #1a1a2e;
}
.swc-chip-icon { font-size: .9rem; }

/* Drop target highlight when a chip is dragged over the page body. */
body.sw-compose-on.swc-bank-dragging [data-section-id] {
    outline-color: color-mix(in srgb, var(--swc-accent) 80%, transparent);
}
.swc-restore-zone {
    block-size: 0;
    overflow: hidden;
    border-radius: var(--swc-radius);
    border: 2px dashed transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--swc-accent);
    font-size: .82rem;
    font-weight: 500;
    background: color-mix(in srgb, var(--swc-accent) 8%, transparent);
    transition: block-size .18s var(--swc-ease), margin-block .18s ease, border-color .15s ease;
}
.swc-restore-zone.swc-slot-live {
    block-size: 46px;
    margin-block: 10px;
    border-color: color-mix(in srgb, var(--swc-accent) 60%, transparent);
}

/* ============================================================
   5. Motion layer — Road-Runner "dust-trail"
   ============================================================ */

/* The flying ghost of an object being sent to / from the bank. */
.sw-compose-flyer {
    position: fixed;
    z-index: 110;
    pointer-events: none;
    border-radius: var(--swc-radius);
    background: color-mix(in srgb, var(--swc-accent) 22%, var(--card, #fff));
    border: 1px solid var(--swc-accent);
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
    will-change: transform, opacity;
}

/* A single dust puff spawned along the flight path. */
.sw-compose-trail {
    position: fixed;
    z-index: 109;
    pointer-events: none;
    inline-size: 14px;
    block-size: 14px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--swc-accent) 45%, #cbd5e1);
    opacity: 0;
    will-change: transform, opacity;
    animation: swc-dust 450ms ease-out forwards;
}

@keyframes swc-dust {
    0%   { opacity: .7; transform: scale(.4) translate(0, 0); }
    60%  { opacity: .5; }
    100% { opacity: 0;  transform: scale(1.5) translate(var(--swc-dx, 0), var(--swc-dy, 6px)); }
}

/* Remove: bounce once, then fade away toward the bank. */
@keyframes swc-eject {
    0%   { transform: scale(1)    rotate(0);     opacity: 1; }
    22%  { transform: scale(1.04) rotate(-1.5deg); opacity: 1; }
    45%  { transform: scale(.94)  rotate(2deg);  opacity: .9; }
    100% { transform: scale(.5)   rotate(-6deg); opacity: 0; }
}
.swc-ejecting { animation: swc-eject 450ms var(--swc-ease) both; }

/* Restore: drop in from the bank with a settle bounce. */
@keyframes swc-land {
    0%   { transform: scale(.5)  translateY(-18px); opacity: 0; }
    55%  { transform: scale(1.04) translateY(3px);  opacity: 1; }
    78%  { transform: scale(.98) translateY(-2px); }
    100% { transform: scale(1)   translateY(0);     opacity: 1; }
}
.swc-landing { animation: swc-land 450ms var(--swc-ease) both; }

/* Move: a quick squash-settle when an object arrives at a new slot. */
@keyframes swc-settle {
    0%   { transform: translateY(-10px) scale(.97); }
    60%  { transform: translateY(3px)   scale(1.02); }
    100% { transform: translateY(0)     scale(1); }
}
.swc-settling { animation: swc-settle 380ms var(--swc-ease) both; }

@keyframes swc-pop-in {
    0%   { transform: scale(.7); opacity: 0; }
    100% { transform: scale(1);  opacity: 1; }
}

/* The flyer's own travel animation is driven inline by JS (it needs
   the measured from/to coordinates), so no keyframe block here. */

/* ---- animations OFF — kill every motion, keep the layout changes ---- */
body[data-animations="off"].sw-compose-on [data-section-id],
body[data-animations="off"] .sw-compose-tray,
body[data-animations="off"] .swc-chrome,
body[data-animations="off"] .swc-slot,
body[data-animations="off"] .swc-undo-bar,
body[data-animations="off"] .swc-chip {
    transition: none !important;
}
body[data-animations="off"] .sw-compose-flyer,
body[data-animations="off"] .sw-compose-trail {
    display: none !important;
}
body[data-animations="off"] .swc-ejecting,
body[data-animations="off"] .swc-landing,
body[data-animations="off"] .swc-settling,
body[data-animations="off"] .swc-undo-bar {
    animation: none !important;
}

/* Respect the OS-level reduced-motion preference too. */
@media (prefers-reduced-motion: reduce) {
    .sw-compose-flyer,
    .sw-compose-trail { display: none !important; }
    .swc-ejecting,
    .swc-landing,
    .swc-settling { animation-duration: 1ms !important; }
}

/* ============================================================
   6. RTL — logical properties already flip; this only nudges
      the dust direction default so the puff still trails sensibly.
   ============================================================ */
[dir="rtl"] .sw-compose-trail { --swc-dx: 0; }

/* ============================================================
   7. "➕ Create a new box" — declare a user object type (D4d-3)
   ============================================================ */
.sw-compose-create {
    margin-block-start: 10px;
    padding-block-start: 10px;
    border-block-start: 1px solid var(--swc-border, rgba(0,0,0,.12));
}
.sw-compose-create-toggle {
    inline-size: 100%;
    padding: 9px 12px;
    border: 1px dashed var(--swc-border, rgba(0,0,0,.3));
    border-radius: 10px;
    background: transparent;
    color: var(--text, #1a1a2e);
    font-size: .9rem;
    cursor: pointer;
}
.sw-compose-create-toggle:hover {
    background: var(--swc-hover, rgba(0,0,0,.04));
}
.sw-compose-create-form {
    margin-block-start: 10px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.swc-create-title {
    margin: 0;
    font-size: .95rem;
    color: var(--text, #1a1a2e);
}
.swc-create-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: .8rem;
    color: var(--muted, #6b7280);
}
.swc-create-row input,
.swc-create-row textarea {
    padding: 7px 9px;
    border: 1px solid var(--swc-border, rgba(0,0,0,.2));
    border-radius: 8px;
    font: inherit;
    font-size: .9rem;
    color: var(--text, #1a1a2e);
    background: var(--card-bg, #fff);
}
.swc-create-row textarea { resize: vertical; }
.swc-create-hint {
    margin: 0;
    font-size: .75rem;
    color: var(--muted, #6b7280);
}
.swc-create-actions {
    display: flex;
    gap: 8px;
}
.swc-create-msg {
    margin: 0;
    font-size: .8rem;
    min-block-size: 1em;
}

/* ============================================================
   8. Object-bank "Add an object" section (D4d-3)
   ============================================================ */
.sw-compose-add {
    margin-block-start: 10px;
    padding-block-start: 10px;
    border-block-start: 1px solid var(--swc-border, rgba(0,0,0,.12));
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.sw-compose-add-title {
    inline-size: 100%;
    margin: 0 0 2px;
    font-size: .82rem;
    color: var(--muted, #6b7280);
}
.swc-chip-add {
    font: inherit;
    cursor: pointer;
    border: 1px dashed var(--swc-border, rgba(0,0,0,.3));
    background: transparent;
}
.swc-chip-add:hover {
    background: var(--swc-hover, rgba(0,0,0,.04));
    border-style: solid;
}
.swc-chip-add[disabled] { opacity: .5; cursor: default; }
.swc-chip-add .swc-chip-restore { color: #16a34a; }

/* ============================================================
   9. Lightning + smoke sub-out effect ("both layered")
   ------------------------------------------------------------
   A bolt strikes the object, then it crumbles into a billowing
   smoke cloud. Driven by lightningStrike() + spawnSmoke() in
   sw-compose.js. All three elements are body-level overlays.
   ============================================================ */
.swc-bolt {
    position: fixed;
    z-index: 9999;
    pointer-events: none;
    overflow: visible;
    animation: swc-bolt-flicker 200ms steps(1, end) both;
}
.swc-bolt-glow {
    fill: none;
    stroke: #fde68a;
    stroke-width: 9;
    stroke-linecap: round;
    stroke-linejoin: round;
    opacity: .55;
    filter: blur(3px);
}
.swc-bolt-core {
    fill: none;
    stroke: #fffbe8;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}
@keyframes swc-bolt-flicker {
    0%   { opacity: 0; }
    10%  { opacity: 1; }
    24%  { opacity: .25; }
    40%  { opacity: 1; }
    100% { opacity: 0; }
}
.swc-bolt-flash {
    position: fixed;
    z-index: 9998;
    pointer-events: none;
    border-radius: 12px;
    background: radial-gradient(circle,
        rgba(255,251,232,.95), rgba(253,230,138,.42) 58%, transparent 76%);
    animation: swc-bolt-flash-kf 200ms ease-out both;
}
@keyframes swc-bolt-flash-kf {
    0%   { opacity: 0; transform: scale(.92); }
    16%  { opacity: 1; transform: scale(1.05); }
    100% { opacity: 0; transform: scale(1.12); }
}
.swc-smoke {
    position: fixed;
    z-index: 9997;
    pointer-events: none;
    border-radius: 50%;
    opacity: .55;
    background: radial-gradient(circle at 38% 34%,
        rgba(226,232,240,.95), rgba(148,163,184,.6) 45%, rgba(100,116,139,0) 72%);
    filter: blur(5px);
    will-change: transform, opacity;
}
/* Honour the per-user Animations OFF setting + OS reduced-motion. */
body[data-animations="off"] .swc-bolt,
body[data-animations="off"] .swc-bolt-flash,
body[data-animations="off"] .swc-smoke {
    display: none !important;
}
@media (prefers-reduced-motion: reduce) {
    .swc-bolt,
    .swc-bolt-flash,
    .swc-smoke { display: none !important; }
}
