/* PatchWork — Simplified Mode (mobile-friendly review UI)
   Overlay above canvas; pure DOM, no LiteGraph. */

#simplified-mode-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-primary, #2a2a2a);
    color: var(--text-primary, #f0f0f0);
    display: flex;
    flex-direction: column;
    font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
    overflow: hidden;
}
#simplified-mode-overlay[hidden] { display: none !important; }

/* ---------- Header ---------- */
.sm-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--bg-secondary, #000);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    gap: 10px;
    min-height: 56px;
}
.sm-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    overflow: hidden;
}
.sm-header-title-wrap { flex: 1; overflow: hidden; }
.sm-header-title {
    font-weight: 600;
    font-size: 17px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sm-header-sub {
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    margin-top: 1px;
}
.sm-header-icon-btn {
    background: transparent;
    color: var(--text-secondary, #a0a0a0);
    border: 1px solid rgba(255,255,255,0.12);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    transition: background 0.15s, color 0.15s;
}
.sm-header-icon-btn:active { background: rgba(255,255,255,0.08); }
.sm-header-icon-btn:hover { color: var(--text-primary, #f0f0f0); }

/* ---------- Wipe + Run buttons (header, project view) ---------- */
.sm-wipe-btn {
    color: var(--text-secondary, #a0a0a0);
}
.sm-wipe-btn:active { background: rgba(255,255,255,0.08); }
.sm-wipe-btn:hover { color: var(--text-primary, #f0f0f0); }
.sm-run-btn {
    color: var(--accent, #5ba4cf);
    border-color: rgba(91,164,207,0.4);
}
.sm-run-btn:active { background: rgba(91,164,207,0.12); }
.sm-run-btn:hover { color: var(--accent-hover, #7dbde8); }

/* ---------- Hamburger drawer ---------- */
.sm-drawer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0);
    z-index: 10003;
    transition: background 0.2s;
}
.sm-drawer-overlay.sm-drawer-open {
    background: rgba(0,0,0,0.5);
}
.sm-drawer {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    width: min(280px, 80vw);
    background: var(--bg-secondary, #1a1a1a);
    border-right: 1px solid rgba(255,255,255,0.08);
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    display: flex;
    flex-direction: column;
}
.sm-drawer-open .sm-drawer { transform: translateX(0); }

.sm-drawer-header {
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sm-drawer-account {
    margin: 12px 12px 4px;
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(91,164,207,0.08);
    border: 1px solid rgba(91,164,207,0.20);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sm-drawer-account-in {
    background: rgba(255,255,255,0.04);
    border-color: rgba(255,255,255,0.08);
}
.sm-drawer-account-avatar {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(91,164,207,0.18);
    color: var(--accent, #5ba4cf);
    display: flex;
    align-items: center;
    justify-content: center;
}
.sm-drawer-account-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.sm-drawer-account-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #f0f0f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sm-drawer-account-email {
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}
.sm-drawer-account-out {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: rgba(255,255,255,0.06);
    color: var(--text-secondary, #a0a0a0);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.sm-drawer-account-out:hover {
    background: rgba(220,80,80,0.18);
    color: #ff8888;
}
.sm-drawer-account-signin {
    flex: 1;
    background: transparent;
    border: 0;
    padding: 0;
    color: inherit;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: left;
}
.sm-drawer-account-icon {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--accent, #5ba4cf);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sm-drawer-account-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    min-width: 0;
}
.sm-drawer-account-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #f0f0f0);
}
.sm-drawer-account-hint {
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    margin-top: 2px;
    white-space: normal;
    line-height: 1.3;
}
.sm-drawer-title { font-size: 18px; font-weight: 700; color: var(--text-primary, #f0f0f0); }
.sm-drawer-sub { font-size: 12px; color: var(--text-secondary, #a0a0a0); margin-top: 2px; }
.sm-drawer-list {
    padding: 8px 0;
    overflow-y: auto;
    flex: 1;
}
.sm-drawer-item {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-primary, #f0f0f0);
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 56px;
    -webkit-tap-highlight-color: transparent;
}
.sm-drawer-item:active { background: rgba(255,255,255,0.04); }
.sm-drawer-icon {
    flex: 0 0 36px;
    width: 36px; height: 36px;
    border-radius: 10px;
    background: rgba(255,255,255,0.06);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-primary, #f0f0f0);
}
.sm-drawer-item-body {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}
.sm-drawer-item-label {
    font-size: 14px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sm-drawer-item-hint {
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---------- Lightbox ---------- */
.sm-lightbox {
    position: fixed;
    inset: 0;
    z-index: 10004;
    background: rgba(0,0,0,0.95);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.18s ease-out;
}
.sm-lightbox.sm-lightbox-open { opacity: 1; }
.sm-lightbox-media {
    max-width: 96vw;
    max-height: 92vh;
    object-fit: contain;
    display: block;
}
.sm-lightbox-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.sm-lightbox-close:active { transform: scale(0.92); background: rgba(255,255,255,0.16); }

/* ---------- Video placeholder ---------- */
.sm-media-video-placeholder {
    background: linear-gradient(135deg, #1a1a1a, #0a0a0a) !important;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sm-media-play-icon {
    color: rgba(255,255,255,0.5);
    pointer-events: none;
}
.sm-clip-video-ph {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a1a, #0a0a0a);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.45);
}
.sm-context-child-video {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: #111;
    color: rgba(255,255,255,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ---------- Logs viewer ---------- */
.sm-logs-inner { padding: 0; display: flex; flex-direction: column; max-height: 85vh; }
.sm-logs-refresh {
    width: 36px; height: 36px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: var(--text-secondary, #a0a0a0);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.sm-logs-refresh:active { background: rgba(255,255,255,0.06); }
.sm-logs-filters {
    display: flex;
    gap: 6px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    overflow-x: auto;
    flex: 0 0 auto;
}
.sm-logs-filters::-webkit-scrollbar { display: none; }
.sm-logs-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 8px 0;
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-size: 12px;
    min-height: 200px;
}
.sm-log-row {
    display: flex;
    gap: 8px;
    padding: 5px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    line-height: 1.4;
    word-break: break-word;
}
.sm-log-time {
    flex: 0 0 auto;
    color: var(--text-secondary, #707070);
    font-size: 11px;
}
.sm-log-msg { flex: 1; white-space: pre-wrap; }
.sm-log-info .sm-log-msg { color: var(--text-primary, #f0f0f0); }
.sm-log-success .sm-log-msg { color: #4ade80; }
.sm-log-warning .sm-log-msg { color: #fbbf24; }
.sm-log-error .sm-log-msg { color: #ef4444; }
.sm-logs-empty {
    padding: 40px 24px;
    text-align: center;
    color: var(--text-secondary, #a0a0a0);
    font-size: 13px;
    font-family: 'DM Sans', system-ui, sans-serif;
}

/* ---------- Activity heatmap ---------- */
.sm-activity-inner { padding: 0; }
.sm-activity-totals {
    display: flex;
    padding: 16px 20px;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.sm-activity-stat {
    flex: 1;
    background: var(--bg-primary, #2a2a2a);
    border-radius: 10px;
    padding: 12px;
    text-align: center;
}
.sm-activity-stat-num {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary, #f0f0f0);
}
.sm-activity-stat-label {
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}
.sm-heatmap-wrap {
    padding: 18px 20px;
}
.sm-heatmap-grid {
    display: grid;
    grid-template-columns: repeat(var(--sm-heatmap-weeks, 12), 1fr);
    gap: 3px;
    margin-bottom: 14px;
}
.sm-heatmap-cell {
    aspect-ratio: 1;
    border-radius: 4px;
    background: rgba(255,255,255,0.08);
    min-width: 14px;
    min-height: 14px;
    border: 1px solid rgba(255,255,255,0.04);
}
.sm-heatmap-cell-empty { background: transparent; border-color: transparent; }
.sm-heatmap-cell-0 { background: rgba(255,255,255,0.08); }
.sm-heatmap-cell-1 { background: rgba(91,164,207,0.35); }
.sm-heatmap-cell-2 { background: rgba(91,164,207,0.55); }
.sm-heatmap-cell-3 { background: rgba(91,164,207,0.75); }
.sm-heatmap-cell-4 { background: rgba(91,164,207,1); }
.sm-heatmap-legend {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
}
.sm-heatmap-legend .sm-heatmap-cell {
    width: 14px; height: 14px;
    aspect-ratio: auto;
}
.sm-activity-note {
    padding: 0 20px 20px;
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    text-align: center;
    line-height: 1.4;
}

/* ---------- Workflow tab strip (project view) ---------- */
.sm-workflow-tabs {
    flex: 0 0 auto;
    display: flex;
    gap: 4px;
    padding: 6px 12px 0;
    background: var(--bg-secondary, #000);
    overflow-x: auto;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}
.sm-workflow-tabs[hidden] { display: none !important; }
.sm-workflow-tabs::-webkit-scrollbar { display: none; }
.sm-workflow-tab {
    flex: 0 0 auto;
    background: transparent;
    color: var(--text-secondary, #a0a0a0);
    border: none;
    border-bottom: 2px solid transparent;
    padding: 8px 12px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 36px;
}
.sm-workflow-tab:active { background: rgba(255,255,255,0.04); }
.sm-workflow-tab-active {
    color: var(--text-primary, #f0f0f0);
    border-bottom-color: var(--accent, #5ba4cf);
}

/* ---------- Share row + URL box ---------- */
.sm-share-row {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}
.sm-share-btn {
    flex: 0 0 auto;
    padding: 0 14px;
    min-height: 36px;
    font-size: 13px;
}
.sm-share-urlbox {
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    padding: 12px;
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-size: 12px;
    word-break: break-all;
    -webkit-user-select: all;
    user-select: all;
    margin: 12px 0;
    color: var(--text-primary, #f0f0f0);
    max-height: 100px;
    overflow-y: auto;
}

/* ---------- Import confirm dialog ---------- */
.sm-import-desc {
    font-size: 13px;
    color: var(--text-secondary, #a0a0a0);
    line-height: 1.4;
    margin-bottom: 14px;
}
.sm-import-confirm .sm-btn { margin-bottom: 8px; }

/* ---------- Filter chip row ---------- */
.sm-filter-row {
    flex: 0 0 auto;
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg-secondary, #000);
    border-bottom: 1px solid rgba(255,255,255,0.06);
    overflow-x: auto;
}
.sm-filter-row[hidden] { display: none !important; }
.sm-filter-row::-webkit-scrollbar { display: none; }
.sm-chip {
    flex: 0 0 auto;
    background: transparent;
    color: var(--text-secondary, #a0a0a0);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 100px;
    padding: 7px 12px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.sm-chip:active { transform: scale(0.97); }
.sm-chip-active {
    background: var(--accent, #5ba4cf);
    border-color: var(--accent, #5ba4cf);
    color: #fff;
}
.sm-chip-count {
    display: inline-block;
    min-width: 18px;
    padding: 0 5px;
    background: rgba(255,255,255,0.12);
    border-radius: 9px;
    font-size: 11px;
    line-height: 16px;
    font-weight: 600;
    text-align: center;
}
.sm-chip-active .sm-chip-count {
    background: rgba(255,255,255,0.25);
    color: #fff;
}

/* ---------- Body scroll ---------- */
.sm-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 14px 12px 32px;
}
.sm-empty {
    text-align: center;
    color: var(--text-secondary, #a0a0a0);
    padding: 60px 24px;
    font-size: 14px;
    line-height: 1.5;
}
.sm-empty-icon { font-size: 40px; margin-bottom: 12px; opacity: 0.4; }

/* ---------- Project card (home) ---------- */
.sm-project-card {
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 14px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, transform 0.1s;
}
.sm-project-card:active { transform: scale(0.99); background: rgba(255,255,255,0.03); }
.sm-project-top { flex: 1; overflow: hidden; }
.sm-project-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #f0f0f0);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sm-project-meta {
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    margin-top: 3px;
}
.sm-project-open {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 6px 14px;
    font-size: 13px;
}

/* ---------- Card (approval / output) ---------- */
.sm-card {
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    margin-bottom: 14px;
    overflow: hidden;
}
.sm-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    gap: 8px;
}
.sm-card-title {
    font-size: 14px;
    font-weight: 600;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sm-card-meta {
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    padding: 3px 8px;
    background: rgba(255,255,255,0.06);
    border-radius: 8px;
    flex: 0 0 auto;
}

/* ---------- Pages inside approval card ---------- */
.sm-page {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sm-page:last-child { border-bottom: none; }
.sm-page-label {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary, #a0a0a0);
    margin-bottom: 8px;
}
.sm-page-status-pending { color: var(--text-secondary, #a0a0a0); }
.sm-page-status-approved { color: #4ade80; }

/* ---------- Media grid ---------- */
.sm-media-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 8px;
}
.sm-media-item {
    position: relative;
    aspect-ratio: 1;
    border: 2px solid transparent;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    background: #111;
    -webkit-tap-highlight-color: transparent;
    transition: border-color 0.15s, transform 0.1s;
}
.sm-media-item:active { transform: scale(0.97); }
.sm-media-item-approved {
    border-color: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.2);
}
.sm-media-item img,
.sm-media-item video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.sm-media-check {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #4ade80;
    color: #000;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
}
.sm-media-item-approved .sm-media-check { display: flex; }
.sm-media-video-badge {
    position: absolute;
    bottom: 6px;
    left: 6px;
    background: rgba(0,0,0,0.65);
    color: #fff;
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 500;
}
.sm-scene-btn {
    position: absolute;
    bottom: 6px;
    right: 6px;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.sm-scene-btn:active { transform: scale(0.9); background: var(--accent, #5ba4cf); }

/* ---------- Context expander ---------- */
.sm-context-wrap {
    border-top: 1px solid rgba(255,255,255,0.05);
}
.sm-context-toggle {
    width: 100%;
    background: transparent;
    color: var(--text-secondary, #a0a0a0);
    border: none;
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.sm-context-toggle:active { background: rgba(255,255,255,0.04); }
.sm-context-body {
    padding: 0 14px 12px;
}
.sm-context-row {
    display: flex;
    gap: 12px;
    padding: 8px 0;
    align-items: flex-start;
}
.sm-context-label {
    flex: 0 0 60px;
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding-top: 2px;
}
.sm-context-value {
    flex: 1;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.4;
}
.sm-context-child {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.sm-context-child img,
.sm-context-child video {
    width: 28px;
    height: 28px;
    object-fit: cover;
    border-radius: 4px;
    background: #111;
}
.sm-context-child-placeholder {
    width: 28px;
    height: 28px;
    border-radius: 4px;
    background: rgba(255,255,255,0.06);
}
.sm-context-ref-missing {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239,68,68,0.12);
    color: #ef4444;
    font-size: 14px;
}
.sm-context-ref-warn {
    color: #ef4444;
    font-size: 11px;
}

/* ---------- Card actions ---------- */
.sm-card-actions {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    background: rgba(0,0,0,0.2);
}
.sm-btn {
    flex: 1;
    min-height: 44px;
    border-radius: 10px;
    border: 1px solid rgba(255,255,255,0.15);
    background: transparent;
    color: var(--text-primary, #f0f0f0);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
    transition: background 0.15s, transform 0.1s, opacity 0.15s;
    padding: 0 12px;
}
.sm-btn:active { transform: scale(0.97); }
.sm-btn-primary {
    background: var(--accent, #5ba4cf);
    border-color: var(--accent, #5ba4cf);
    color: #fff;
}
.sm-btn-secondary { background: transparent; }
.sm-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Scene view ---------- */
.sm-scene-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    overflow-x: auto;
}
.sm-scene-tabs::-webkit-scrollbar { display: none; }
.sm-scene-tab {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--text-secondary, #a0a0a0);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
}
.sm-scene-tab-active {
    background: var(--accent, #5ba4cf);
    border-color: var(--accent, #5ba4cf);
    color: #fff;
}
.sm-scene-tab-count {
    background: rgba(255,255,255,0.12);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 600;
}
.sm-scene-tab-active .sm-scene-tab-count {
    background: rgba(255,255,255,0.25);
}
.sm-scene-tab-add {
    padding: 8px 10px;
    color: var(--text-secondary, #a0a0a0);
    border-style: dashed;
    border-color: rgba(255,255,255,0.18);
    background: transparent;
}
.sm-scene-tab-add:hover {
    color: var(--text-primary, #f0f0f0);
    border-color: rgba(91,164,207,0.55);
    background: rgba(91,164,207,0.08);
}

.sm-clip-list {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 12px;
    padding: 4px 4px 14px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    overscroll-behavior-x: contain;
}
.sm-clip-list::-webkit-scrollbar { height: 6px; }
.sm-clip-list::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.12);
    border-radius: 3px;
}
.sm-clip-card {
    position: relative;
    flex: 0 0 auto;
    /* Show ~2.2 cards on a typical 375px phone (each ~169px) — user sees 2-3 at once */
    width: min(45vw, 200px);
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    overflow: hidden;
    transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s ease;
    will-change: transform;
    scroll-snap-align: start;
}
.sm-clip-card-dragging {
    transition: none !important;
    z-index: 10;
    box-shadow: 0 12px 32px rgba(0,0,0,0.55), 0 0 0 1px rgba(91,164,207,0.35);
}
body.sm-clip-dragging { -webkit-user-select: none; user-select: none; }
body.sm-clip-dragging * { cursor: grabbing !important; }
.sm-clip-thumb {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #0a0a0a;
    overflow: hidden;
}
.sm-clip-thumb img,
.sm-clip-thumb video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.sm-clip-order {
    position: absolute;
    top: 6px;
    left: 6px;
    z-index: 2;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    background: rgba(0,0,0,0.66);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
}
.sm-clip-drag {
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 3;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 8px;
    background: rgba(0,0,0,0.55);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    color: rgba(255,255,255,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    padding: 0;
    touch-action: none; /* let the drag take over from scroll */
}
.sm-clip-drag:active { cursor: grabbing; background: rgba(0,0,0,0.75); }
.sm-clip-remove {
    position: absolute;
    bottom: 6px;
    right: 6px;
    z-index: 3;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 8px;
    background: rgba(0,0,0,0.6);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #fff;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    font-family: inherit;
    padding: 0;
}
.sm-clip-remove:hover { background: rgba(220,80,80,0.7); }
.sm-clip-remove:active { transform: scale(0.92); }
.sm-clip-footer {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    padding: 8px 10px 10px;
}
.sm-clip-name {
    font-size: 12px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    color: var(--text-primary, #f0f0f0);
}
.sm-clip-dur {
    font-size: 11px;
    color: var(--text-secondary, #a0a0a0);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}
.sm-clip-total {
    margin-top: 14px;
    padding: 10px;
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    background: rgba(255,255,255,0.03);
    border-radius: 8px;
}

/* Generations picker (long-press a clip card to open) */
.sm-gen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.sm-gen-header .sm-sheet-title { margin: 0; }
.sm-gen-hint {
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    margin-bottom: 10px;
}
.sm-gen-rerun-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--accent, #5ba4cf);
    border-radius: 999px;
    background: rgba(91,164,207,0.12);
    color: var(--accent, #5ba4cf);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
}
.sm-gen-rerun-btn:hover { background: rgba(91,164,207,0.22); }
.sm-gen-rerun-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.sm-gen-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 4px 0 12px;
}
.sm-gen-tile {
    position: relative;
    padding: 0;
    border: 2px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    overflow: hidden;
    background: #0a0a0a;
    cursor: pointer;
    font-family: inherit;
    aspect-ratio: 16 / 9;
    width: 100%;
}
.sm-gen-tile img,
.sm-gen-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.sm-gen-tile-ph {
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #1a1a1a, #0a0a0a);
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.45);
}
.sm-gen-tile-label {
    position: absolute;
    left: 6px;
    bottom: 6px;
    z-index: 2;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(0,0,0,0.65);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
}
.sm-gen-tile-current {
    border-color: var(--accent, #5ba4cf);
    box-shadow: 0 0 0 2px rgba(91,164,207,0.45);
}
.sm-gen-tile-current::after {
    content: '\2713'; /* check mark */
    position: absolute;
    top: 6px;
    right: 6px;
    z-index: 2;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--accent, #5ba4cf);
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sm-gen-empty {
    padding: 24px;
    text-align: center;
    color: var(--text-secondary, #a0a0a0);
    font-size: 13px;
}

/* ---------- Sheet (bottom slide-up) ---------- */
.sm-sheet {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 10001;
    display: flex;
    align-items: flex-end;
    animation: sm-fade-in 0.2s;
}
@keyframes sm-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}
.sm-sheet-inner {
    width: 100%;
    max-height: 80vh;
    background: var(--bg-primary, #2a2a2a);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    padding: 16px;
    overflow-y: auto;
    animation: sm-slide-up 0.25s;
}
@keyframes sm-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}
.sm-sheet-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    text-align: center;
}
.sm-sheet-row {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-secondary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 10px;
    margin-bottom: 8px;
    color: var(--text-primary, #f0f0f0);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    text-align: left;
}
.sm-sheet-row:active { background: rgba(255,255,255,0.04); }
.sm-sheet-row-count {
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    font-weight: 400;
}
.sm-sheet-cancel {
    width: 100%;
    margin-top: 8px;
    padding: 14px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-secondary, #a0a0a0);
    font-size: 14px;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
}

/* ---------- Settings sheet ---------- */
.sm-settings-sheet .sm-sheet-inner {
    max-height: 90vh;
    border-radius: 16px;
    margin: auto 8px 8px;
    align-self: flex-end;
}
@media (min-width: 768px) {
    .sm-settings-sheet .sm-sheet-inner {
        max-width: 540px;
        margin: auto;
        align-self: center;
        border-radius: 16px;
    }
    .sm-settings-sheet { align-items: center; justify-content: center; }
}
.sm-settings-inner { padding: 0; }
.sm-settings-titlebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    background: var(--bg-secondary, #1a1a1a);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    position: sticky;
    top: 0;
    z-index: 1;
}
.sm-settings-titlebar .sm-sheet-title { margin: 0; }
.sm-settings-close {
    background: transparent;
    border: none;
    color: var(--text-secondary, #a0a0a0);
    font-size: 28px;
    line-height: 1;
    width: 36px; height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
}
.sm-settings-close:active { background: rgba(255,255,255,0.06); }
.sm-settings-group {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sm-settings-group-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-primary, #f0f0f0);
}
.sm-settings-group-hint {
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    margin-bottom: 12px;
    line-height: 1.4;
}
.sm-settings-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary, #1a1a1a);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: var(--text-primary, #f0f0f0);
    font-size: 14px;
    font-family: inherit;
    box-sizing: border-box;
}
.sm-settings-input:focus { outline: 1px solid var(--accent, #5ba4cf); }
.sm-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    cursor: pointer;
}
.sm-toggle-row input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--accent, #5ba4cf);
}
.sm-key-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.sm-key-row {
    display: grid;
    grid-template-columns: 1fr 100px 32px;
    gap: 6px;
    align-items: center;
}
.sm-key-row .sm-key-label { font-size: 12px; }
.sm-key-remove {
    width: 32px; height: 32px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.12);
    color: var(--text-secondary, #a0a0a0);
    border-radius: 8px;
    font-size: 18px;
    cursor: pointer;
    font-family: inherit;
}
.sm-key-empty {
    font-size: 12px;
    color: var(--text-secondary, #a0a0a0);
    font-style: italic;
    padding: 6px 0;
}

/* ---------- Toast ---------- */
.sm-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.85);
    color: #fff;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 10002;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
}
.sm-toast-show { opacity: 1; }

/* ---------- Mobile fine-tuning ---------- */
@media (max-width: 480px) {
    .sm-media-grid { grid-template-columns: repeat(2, 1fr); }
    .sm-body { padding: 12px 10px 24px; }
    .sm-card { margin-bottom: 12px; }
    .sm-key-row {
        grid-template-columns: 1fr 32px;
        grid-template-rows: auto auto;
    }
    .sm-key-row .sm-key-label { grid-column: 1 / 2; }
    .sm-key-row .sm-key-remove { grid-row: 1; grid-column: 2; }
}
@media (min-width: 768px) {
    .sm-body { padding: 24px; }
    .sm-card, .sm-project-card { max-width: 720px; margin-left: auto; margin-right: auto; }
    .sm-media-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
    .sm-filter-row { padding: 12px 24px; }
}
